package cn.changeforyou.web.nutz.common.security;

import cn.changeforyou.web.blog.po.User;
import org.nutz.ioc.loader.annotation.IocBean;

/**
 * @author zhyu
 * @date 2021/5/26 13:29
 */
@IocBean
public class AuthUtil {

    private ThreadLocal<User> currentUser = new ThreadLocal<>();

    public void setUser(User user) {
        currentUser.set(user);
    }

    public User getAndValid() {
        User user = currentUser.get();
        if (null == user) {
            throw new AuthException("验证失败,请重新登录");
        }
        return user;
    }
}
